<?php
namespace Admin\Controller;
use Think\Controller;
/**代理控制器**/
class MemberController extends AdminController {
	//代理列表
	public function index(){
		D('Member')->set_agentid();
	}

	//成为代理支付
	public function pay($id){

		//获取该级别费用
		$order_sn = date('YmdHis').UID;
		$fee = 1;
		$param = [
			'fee'		=>	$fee,		//费用
			'body'		=>	'测试', 	//描述
			'attach'	=>	'...',		//附加数据
			'order_sn'	=>	$order_sn,	//订单号
			'goods_tag'	=>	'成为代理',
			'url'		=>	C('MemberRechargeUrl.BeMember'),
			'product'	=>	10001,
		];
		$url = wxpay($param);
		$member = M('Member')->find(UID);
		//生成订单
		$orders = [
			'agentID'	=>	$member['agentid'],
			'username'	=>	$member['username'],
			'amount'	=>	$fee,
			'type'		=>	C('MemberRechargeType.BeMember'),
			'status'	=>	0,
			'create_time'=>	time(),
			'order_sn'	=>	$order_sn
		];
		$res = M('Memberorders')->add($orders);
		if(!$res){
			$this->error('生成订单时发生错误');
		} 
		if($url){
			$info = [
				'order_sn'	=>	$order_sn,
				'url'		=>	$url,
			]; 
			$this->success($info);
		}else{
			$this->error('失败');
		}
	}
	public function chkorder($order_sn){
		$order = M('Memberorders')->where(array('order_sn'=>$order_sn))->find();
		if($order['status'] == 1){
			$this->success('购买成功',U('Index/index'));
		}else{
			$this->error('购买失败');
		}
	}

	//账号设置
	public function my(){
		$this->display();
	}	
}
